package com.bds.wm.action;

import com.alibaba.fastjson.JSONObject;
import com.bds.wm.model.common.Result;
import com.bds.wm.model.procmodel.Competitor;
import com.bds.wm.service.CompetitorViewService;
import com.bds.wm.service.ViewService;
import com.bds.wm.utils.CheckParams;
import com.bds.wm.utils.Const;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created by DongChenchen on 2018/7/17 0017
 */
@Controller
public class CompetitorAction {
    private static Logger LOGGER = Logger.getLogger(CompetitorAction.class);
    @Autowired
    private ViewService viewService;
    @Autowired
    private CompetitorViewService competitorViewService;

    @RequestMapping(value = "/service/data/getRegionCityBrandName",method = RequestMethod.GET)
    @ResponseBody
    public Result getRegionCityBrandName(){
        Result result = new Result();
        JSONObject jsonObject = viewService.getRegionCityBrandName();
        result.setResult(Const.SUC, jsonObject);
        return result;
    }
    @RequestMapping(value = "/service/data/getComparisonbyProduct", method = RequestMethod.GET)
    @ResponseBody
    public Result getComparisonbyProduct(String city,String start_time, String end_time,String brand) {
        Result result = new Result();
        Integer start = CheckParams.checkIfIntAndReturn(start_time);
        Integer end = CheckParams.checkIfIntAndReturn(end_time);
        if (start == null || end == null) {
            LOGGER.info("参数异常");
            result.setResult(Const.FAIL, "参数异常");
            return result;
        }
        List<Competitor> cates = competitorViewService.getComparisonbyProduct(city, start, end,brand);
        JSONObject jsonObject = competitorViewService.groupByCategory(cates);
        result.setResult(Const.SUC, jsonObject);
        return result;
    }
    @RequestMapping(value = "/service/data/get_overviewresult_by_citySuCategory2", method = RequestMethod.GET)
    @ResponseBody
    public Result getOverviewResultbyCitySuCategory2(String city,String start_time, String end_time) {
        Result result = new Result();
        Integer start = CheckParams.checkIfIntAndReturn(start_time);
        Integer end = CheckParams.checkIfIntAndReturn(end_time);
        if (start == null || end == null) {
            LOGGER.info("参数异常");
            result.setResult(Const.FAIL, "参数异常");
            return result;
        }
        JSONObject json=new JSONObject();
        List<String> cate1= Lists.newArrayList("品类-披萨","","","￥556,338","23,423,455","","22,313");
        List<String> cate2= Lists.newArrayList("品类-面饭","","","￥324,111","32,445,455","","22,666");
        List<String> cate3= Lists.newArrayList("品类-甜品","","","￥213,455","23,423,675","","22,333");
        List<Object> cate= Lists.newArrayList(cate1,cate2,cate3);
        Map<String, List<Object>> subCateMap = Maps.newLinkedHashMap();
        List<String> subCate1= Lists.newArrayList("超级豪华披萨","10寸","￥34","342,255","23,675","2.2%","302");
        List<String> subCate2= Lists.newArrayList("苏丹王黄金果肉披萨","10寸","￥98","121,455","23,675","1.2%","3,202");
        List<String> subCate3= Lists.newArrayList("新奥尔良披萨","10寸","￥68","445,455","23,475","2.2%","1,002");
        List<String> subCate4= Lists.newArrayList("超级豪华披萨","10寸","￥34","342,255","23,675","2.2%","302");
        List<String> subCate5= Lists.newArrayList("苏丹王黄金果肉披萨","10寸","￥98","121,455","23,675","1.2%","3,202");
        List<String> subCate6= Lists.newArrayList("新奥尔良披萨","10寸","￥68","445,455","23,475","2.2%","1,002");
        List<String> subCate7= Lists.newArrayList("超级豪华披萨","10寸","￥34","342,255","23,675","2.2%","302");
        List<String> subCate8= Lists.newArrayList("苏丹王黄金果肉披萨","10寸","￥98","121,455","23,675","1.2%","3,202");
        List<String> subCate9= Lists.newArrayList("新奥尔良披萨","10寸","￥68","445,455","23,475","2.2%","1002");
        List<String> subCate11= Lists.newArrayList("超级豪华披萨","10寸","￥34","342,255","23,675","2.2%","302");
        List<String> subCate22= Lists.newArrayList("苏丹王黄金果肉披萨","10寸","￥98","121,455","23,675","1.2%","3,202");
        List<String> subCate33= Lists.newArrayList("新奥尔良披萨","10寸","￥68","445,455","23,475","2.2%","1002");
        List<String> subCate44= Lists.newArrayList("超级豪华披萨","10寸","￥34","342,255","23,675","2.2%","302");
        List<String> subCate55= Lists.newArrayList("苏丹王黄金果肉披萨","10寸","￥98","121,455","23,675","1.2%","3,202");
        List<String> subCate66= Lists.newArrayList("新奥尔良披萨","10寸","￥68","445,455","23,475","2.2%","1002");
        List<String> subCate77= Lists.newArrayList("超级豪华披萨","10寸","￥34","342,255","23,675","2.2%","302");
        List<String> subCate88= Lists.newArrayList("苏丹王黄金果肉披萨","10寸","￥98","121,455","23675","1.2%","3,202");
        List<String> subCate99= Lists.newArrayList("新奥尔良披萨","10寸","￥68","445,455","23,475","2.2%","1,002");
        List<Object> sub1= Lists.newArrayList(subCate1,subCate2,subCate3,subCate11,subCate22,subCate33);
        subCateMap.put("品类-披萨",sub1);
        List<Object> sub2= Lists.newArrayList(subCate4,subCate5,subCate6,subCate44,subCate55,subCate66);
        subCateMap.put("品类-面饭",sub2);
        List<Object> sub3= Lists.newArrayList(subCate7,subCate8,subCate9,subCate77,subCate88,subCate99);
        subCateMap.put("品类-甜品",sub3);
        json.put("cate",cate);
        json.put("subCate",subCateMap);
        result.setResult(Const.SUC, json);
        return result;
    }


}
